package cc.mycraft.pvp;

import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

/*		手艺竞技场
 * 
 * 1.安全区 SafeArea 负责安全区无敌工作、安全传入战场
 * 2.商店 ArenaShop 使用指令，用竞技场积分作为货币购买已添加的物品
 * 3.信息显示用：ActionBar Title ServerPackage
 * 4.监听器 PVPListener 监听击杀和死亡，并做成就检测记录。
 * 5.数据记录 PlayerManager 记录积分、击杀、死亡
 * 6.成就 Achievement 检测玩家的击杀、连杀、死亡、积分是否达到特定要求，达到则给头衔权限。
 * 
 */
//主类，初始化各模块、加载指令。
public class Main extends JavaPlugin{
	public static FileConfiguration config;
	public static Main plugin;
	public static ItemStack ArenaChest;
	
	public static Main getPlugin() {
		return plugin;
	}
		
	@Override
	public void onEnable() {
		saveDefaultConfig();
		config = getConfig();
		plugin = this;
		ArenaChest = getConfig().getItemStack("ChestItem");
		getServer().getPluginManager().registerEvents(new PVPListener(), this);
		SafeArea.run();
		PlayerManager.run();
		ArenaShop.run();
		RankingList.run();
		PVPListener.reAddToMap();
		super.onEnable();
	}
	public void onDisable() {
		super.onDisable();
	}
	
	public boolean onCommand(CommandSender s, Command cmd, String label, String[] args) {
		String CmdName = cmd.getName().toLowerCase();
		switch (CmdName) {
		case "pvppointweeklyreset" : 
			if((s instanceof Player)){
				Player se = (Player)s;
				se.sendMessage("该指令只允许控制台执行。");
				return false;
			}
			WeeklyReward WR = new WeeklyReward();
			Bukkit.getLogger().info("结算开始，结算结果请查看控制台。");
			WR.setWeeklyReward();
			break;
		case "pvpbuilding":
			PVPListener.Building = !PVPListener.Building;
			s.sendMessage("Now Building Mode : " + PVPListener.Building);
			return true;
		default:
			break;
		}
		Player p = (Player) s;
		if(!(s instanceof Player)){
			return false;
		}
		switch (CmdName) {
		case "wd":return SafeArea.addGodMode(p);
		case "nwd":return SafeArea.removeGodMode(p);
		case "joinarena":return SafeArea.joinArena(p);
		case "setchest":return SafeArea.setChest(p);
		case "mypvp":PlayerManager.getInfo(p);return true;
		case "re":PVPListener.reAddToMap();return true;
		case "broadcast":
			if(args.length!=1) {
				return false;
			}
			PVPListener.BroadCast(args[0]);return true;
		case "pvpranking":
			RankingList RL = new RankingList();
			RL.setTopList(p);return true;
		case "pvptop":
			if(args.length!=1) {
				return false;
			}
			RankingList.viewTop(p,args[0]);return true;
		case "setpoint":
			if(args.length!=1) {
				return false;
			}
			PlayerManager.setPoint(p, Integer.parseInt(args[0]));return true;
		case "addtoshop":
			if(args.length!=1) {
			return false;
		}
		ArenaShop.addItem(p,args[0]);
		return true;
		case "pvpbuy":
			if(args.length!=1) {
				return false;
			}
			ArenaShop.buyItem(p,args[0]);
			return true;
			default:return false;
		}
	}
}
